//
//  YYCollectionViewCell.m
//  ONE
//
//  Created by 杨毅 on 16/6/7.
//  Copyright © 2016年 GroupNine. All rights reserved.
//

#import "YYCollectionViewCell.h"
#import "YYContentTableViewCell.h"


@implementation YYCollectionViewCell

- (void)dealloc
{
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tableView = [[UITableView alloc] init];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.contentView addSubview:_tableView];
        
        /** 设置头视图 */
        self.headerView = [[UIView alloc] init];
        self.headerView.backgroundColor = [UIColor blueColor];
        self.tableView.tableHeaderView = _headerView;
        
        /** 头视图图片 */
        self.headerImageView = [[UIImageView alloc] init];
        self.headerImageView.image = [UIImage imageNamed:@"music_cover_1729x1729_@1x"];
        [self.headerView addSubview:_headerImageView];
        
        /** 音乐 */
        self.musicView = [[YYMusicView alloc] init];
        [self.headerView addSubview:_musicView];
        
        /** 音乐故事Label */
        self.label = [[UILabel alloc] init];
        self.label.text = @"音乐故事";
        self.label.textAlignment = 0;
        self.label.textColor = [UIColor grayColor];
        self.label.backgroundColor = [UIColor blackColor];
        self.label.font = [UIFont systemFontOfSize:13];
        [self.headerView addSubview:_label];
        
        /** 音乐故事Button */
        self.musicButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //[self.musicButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.musicButton.backgroundColor = [UIColor redColor];
        [self.musicButton addTarget:self action:@selector(didClickedMusicButton:) forControlEvents:UIControlEventTouchDown];
        [self.headerView addSubview:_musicButton];
        
        /** 歌词Button */
        self.lyricsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //[self.lyricsButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.lyricsButton.backgroundColor = [UIColor redColor];
        [self.lyricsButton addTarget:self action:@selector(didClickedLyricsButton:) forControlEvents:UIControlEventTouchDown];
        [self.headerView addSubview:_lyricsButton];

        
        /** 歌曲信息Button */
        self.infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.infoButton.backgroundColor = [UIColor redColor];
        //[self.infoButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [self.infoButton addTarget:self action:@selector(didClickedInfoButton:) forControlEvents:UIControlEventTouchDown];
        [self.headerView addSubview:_infoButton];
        
        
        
        
        
        
        
        /** 注册cell */
        [self.tableView registerClass:[YYContentTableViewCell class] forCellReuseIdentifier:@"cell"];
        
    }
    return self;
}

- (void)layoutSubviews
{
    self.tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    /** 头视图 */
    self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
    
    /** 头视图图片 */
    self.headerImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 3 * 2);
    
    /** 自定义音乐视图 */
    self.musicView.frame = CGRectMake(20, self.headerImageView.bounds.origin.y + self.headerImageView.bounds.size.height - 40, SCREEN_WIDTH - 40, 150);
    self.musicView.backgroundColor = [UIColor blackColor];
    
    /** 音乐故事Label */
    self.label.frame = CGRectMake(15, self.musicView.frame.origin.y + self.musicView.frame.size.height + 20, SCREEN_WIDTH / 2, 20);
    
    /** 音乐故事Button */
    self.musicButton.frame = CGRectMake(self.label.frame.origin.x + self.label.frame.size.width + 15, self.label.frame.origin.y - 5, 25, 25);
    
    /** 歌词Button */
    self.lyricsButton.frame = CGRectMake(self.musicButton.frame.origin.x + self.musicButton.frame.size.width + 35, self.musicButton.frame.origin.y, self.musicButton.frame.size.width, self.musicButton.frame.size.height);
    
    /** 歌曲信息Button */
    self.infoButton.frame = CGRectMake(self.lyricsButton.frame.origin.x + self.lyricsButton.frame.size.width + 35, self.lyricsButton.frame.origin.y, self.musicButton.frame.size.width, self.musicButton.frame.size.height);
    
    
    
}

#pragma mark -- tableView必须实现方法(一)number
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

#pragma mark -- tableView必须实现方法(二)cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YYContentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor orangeColor];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 300;
}

#pragma mark -- sectionNumber
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

#pragma mark -- 音乐故事 Button 点击方法
- (void)didClickedMusicButton:(UIButton *)button
{
    NSLog(@"音乐故事");
}

#pragma mark -- 歌词 Button 点击方法
- (void)didClickedLyricsButton:(UIButton *)button
{
    NSLog(@"歌词");
}

#pragma mark -- 歌曲信息 Button 点击方法
- (void)didClickedInfoButton:(UIButton *)button
{
    NSLog(@"歌曲信息");
}

@end
